package com.example.weight.greenSeasons.compost;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.config.Config;
import com.example.weight.util.Utility;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import net.cachapa.expandablelayout.ExpandableLayout;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class duifeigongyi extends AppCompatActivity {

    private String factory;
    private ExpandableLayout expand_1;
    private ExpandableLayout expand_2;
    private ExpandableLayout expand_3;
    private ExpandableLayout expand_4;
    private Button textView1;
    private Button textView2;
    private Button textView3;
    private Button textView4;
    Calendar calendar= Calendar.getInstance(Locale.CHINA);
    private EditText jinliaodunxiangshuliang1, chulichuyuliang1, nitanyongliang1,
            ganhuachuyushaixiawuyongliang1, mujizhiyongliang1, chuliaodunxiangshuliang1,
            chuyushaixiawuchashengliang1, jinliaodunxiangshuliang2, chulichuyuliang2, nitanyongliang2,
            ganhuachuyushaixiawuyongliang2, mujizhiyongliang2, chuliaodunxiangshuliang2,
            chuyushaixiawuchashengliang2, jinliaodunxiangshuliang3, chulichuyuliang3,
            nitanyongliang3, ganhuachuyushaixiawuyongliang3, mujizhiyongliang3,
            chuliaodunxiangshuliang3, chuyushaixiawuchashengliang3, jinliaodunxiangshuliang4,
            chulichuyuliang4, nitanyongliang4, ganhuachuyushaixiawuyongliang4, mujizhiyongliang4,
            chuliaodunxiangshuliang4, chuyushaixiawuchashengliang4, comment;
    TextView dateEdit;
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date dateEditDate = new Date(System.currentTimeMillis());
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_duifeigongyi);

        Intent previousIntent = getIntent();
        String name = previousIntent.getStringExtra("name");
        factory = previousIntent.getStringExtra("factory");
        expand_1=findViewById(R.id.expandable_1);
        expand_2=findViewById(R.id.expandable_2);
        expand_3=findViewById(R.id.expandable_3);
        expand_4=findViewById(R.id.expandable_4);
        textView1=findViewById(R.id.textView_1);
        textView2=findViewById(R.id.textView_2);
        textView3=findViewById(R.id.textView_3);
        textView4=findViewById(R.id.textView_4);

        jinliaodunxiangshuliang1 = findViewById(R.id.compost_gongyi_jinliaodunxiangshuliang1);
        chulichuyuliang1 = findViewById(R.id.compost_gongyi_chulichuyuliang1);
        nitanyongliang1 = findViewById(R.id.compost_gongyi_nitanyongliang1);
        ganhuachuyushaixiawuyongliang1 = findViewById(R.id.compost_gongyi_ganhuachuyushaixiawuyongliang1);
        mujizhiyongliang1 = findViewById(R.id.compost_gongyi_mujizhiyongliang1);
        chuliaodunxiangshuliang1 = findViewById(R.id.compost_gongyi_chuliaodunxiangshuliang1);
        chuyushaixiawuchashengliang1 = findViewById(R.id.compost_gongyi_chuyushaixiawuchashengliang1);
        jinliaodunxiangshuliang2 = findViewById(R.id.compost_gongyi_jinliaodunxiangshuliang2);
        chulichuyuliang2 = findViewById(R.id.compost_gongyi_chulichuyuliang2);
        nitanyongliang2 = findViewById(R.id.compost_gongyi_nitanyongliang2);
        ganhuachuyushaixiawuyongliang2 = findViewById(R.id.compost_gongyi_ganhuachuyushaixiawuyongliang2);
        mujizhiyongliang2 = findViewById(R.id.compost_gongyi_mujizhiyongliang2);
        chuliaodunxiangshuliang2 = findViewById(R.id.compost_gongyi_chuliaodunxiangshuliang2);
        chuyushaixiawuchashengliang2 = findViewById(R.id.compost_gongyi_chuyushaixiawuchashengliang2);
        jinliaodunxiangshuliang3 = findViewById(R.id.compost_gongyi_jinliaodunxiangshuliang3);
        chulichuyuliang3 = findViewById(R.id.compost_gongyi_chulichuyuliang3);
        nitanyongliang3 = findViewById(R.id.compost_gongyi_nitanyongliang3);
        ganhuachuyushaixiawuyongliang3 = findViewById(R.id.compost_gongyi_ganhuachuyushaixiawuyongliang3);
        mujizhiyongliang3 = findViewById(R.id.compost_gongyi_mujizhiyongliang3);
        chuliaodunxiangshuliang3 = findViewById(R.id.compost_gongyi_chuliaodunxiangshuliang3);
        chuyushaixiawuchashengliang3 = findViewById(R.id.compost_gongyi_chuyushaixiawuchashengliang3);
        jinliaodunxiangshuliang4 = findViewById(R.id.compost_gongyi_jinliaodunxiangshuliang4);
        chulichuyuliang4 = findViewById(R.id.compost_gongyi_chulichuyuliang4);
        nitanyongliang4 = findViewById(R.id.compost_gongyi_nitanyongliang4);
        ganhuachuyushaixiawuyongliang4 = findViewById(R.id.compost_gongyi_ganhuachuyushaixiawuyongliang4);
        mujizhiyongliang4 = findViewById(R.id.compost_gongyi_mujizhiyongliang4);
        chuliaodunxiangshuliang4 = findViewById(R.id.compost_gongyi_chuliaodunxiangshuliang4);
        chuyushaixiawuchashengliang4 = findViewById(R.id.compost_gongyi_chuyushaixiawuchashengliang4);
        comment = findViewById(R.id.compost_gongyi_comment);

        TitleBar titleBar = findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {}

            @Override
            public void onRightClick(View v) {}
        });


        dateEdit = findViewById(R.id.compost_editDate);
        Calendar calendar=Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1; //第一个月从0开始，所以得到月份＋1
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        dateEdit.setText(simpleDateFormat.format(dateEditDate));

        RequestQueue queue = Volley.newRequestQueue(this);
        String url = Config.url + "/sjq/compostCraft/getlast_day" + "?factory=" + factory;
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if (!jsonObject.isNull("data")) {
                                JSONObject data = jsonObject.getJSONObject("data");
                                String temp;
                                temp = data.getString("tontankFeed1");
                                jinliaodunxiangshuliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("disposalKitchenWaste1");
                                chulichuyuliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("peat1");
                                nitanyongliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("driedKitchenWaste1");
                                ganhuachuyushaixiawuyongliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("woodMatrix1");
                                mujizhiyongliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("dischargeTonBox1");
                                chuliaodunxiangshuliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("kitchenWasteUnderSieve1");
                                chuyushaixiawuchashengliang1.setText(temp.equals("null")?"":temp);
                                temp = data.getString("tontankFeed2");
                                jinliaodunxiangshuliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("disposalKitchenWaste2");
                                chulichuyuliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("peat2");
                                nitanyongliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("driedKitchenWaste2");
                                ganhuachuyushaixiawuyongliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("woodMatrix2");
                                mujizhiyongliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("dischargeTonBox2");
                                chuliaodunxiangshuliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("kitchenWasteUnderSieve2");
                                chuyushaixiawuchashengliang2.setText(temp.equals("null")?"":temp);
                                temp = data.getString("tontankFeed3");
                                jinliaodunxiangshuliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("disposalKitchenWaste3");
                                chulichuyuliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("peat3");
                                nitanyongliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("driedKitchenWaste3");
                                ganhuachuyushaixiawuyongliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("woodMatrix3");
                                mujizhiyongliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("dischargeTonBox3");
                                chuliaodunxiangshuliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("kitchenWasteUnderSieve3");
                                chuyushaixiawuchashengliang3.setText(temp.equals("null")?"":temp);
                                temp = data.getString("tontankFeed4");
                                jinliaodunxiangshuliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("disposalKitchenWaste4");
                                chulichuyuliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("peat4");
                                nitanyongliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("driedKitchenWaste4");
                                ganhuachuyushaixiawuyongliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("woodMatrix4");
                                mujizhiyongliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("dischargeTonBox4");
                                chuliaodunxiangshuliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("kitchenWasteUnderSieve4");
                                chuyushaixiawuchashengliang4.setText(temp.equals("null")?"":temp);
                                temp = data.getString("remark");
                                comment.setText(temp.equals("null")?"":temp);
                                Toast.makeText(duifeigongyi.this,
                                        "今日已填写此表", Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(duifeigongyi.this,
                        "获取信息失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
    }

    public void show1(View view) {
        if (expand_1.isExpanded()){
            textView1.setText("+ 1#槽");
        }else{
            textView1.setText("- 1#槽");
            expand_2.collapse();
            expand_3.collapse();
            expand_4.collapse();
        }

        expand_1.toggle();
    }
    public void show2(View view) {
        if (expand_2.isExpanded()){
            textView2.setText("+ 2#槽");
        }else{
            textView2.setText("- 2#槽");
            expand_1.collapse();
            expand_3.collapse();
            expand_4.collapse();
        }

        expand_2.toggle();
    }
    public void show3(View view) {
        if (expand_3.isExpanded()){
            textView3.setText("+ 3#槽");
        }else{
            textView3.setText("- 3#槽");
            expand_1.collapse();
            expand_2.collapse();
            expand_4.collapse();
        }

        expand_3.toggle();
    }
    public void show4(View view) {
        if (expand_4.isExpanded()){
            textView4.setText("+ 4#槽");
        }else{
            textView4.setText("- 4#槽");
            expand_1.collapse();
            expand_2.collapse();
            expand_3.collapse();
        }

        expand_4.toggle();
    }
    //    选择日期
    @SuppressLint({"DefaultLocale", "ResourceType"})
    public void selectDate(View view){
        int YEAR = calendar.get(Calendar.YEAR);
        int MONTH = calendar.get(Calendar.MONTH);
        int DAY = calendar.get(Calendar.DAY_OF_MONTH);
        new DatePickerDialog(this, 2, (view1, year, month, day) -> {
            // 更新EditText控件日期 小于10加0
            dateEdit.setText(new StringBuilder()
                    .append(year)
                    .append("-")
                    .append((month + 1) < 10 ? "0"+ (month + 1) : (month + 1))
                    .append("-")
                    .append((day < 10) ? "0" + day : day));
        },YEAR, MONTH, DAY).show();
    }


    public void save(View view) {
        if (jinliaodunxiangshuliang1.getText().toString().equals("") &&
                chulichuyuliang1.getText().toString().equals("") &&
                nitanyongliang1.getText().toString().equals("") &&
                ganhuachuyushaixiawuyongliang1.getText().toString().equals("") &&
                mujizhiyongliang1.getText().toString().equals("") &&
                chuliaodunxiangshuliang1.getText().toString() .equals("") &&
                chuyushaixiawuchashengliang1.getText().toString().equals("") &&
                jinliaodunxiangshuliang2.getText().toString().equals("") &&
                chulichuyuliang2.getText().toString().equals("") &&
                nitanyongliang2.getText().toString().equals("") &&
                ganhuachuyushaixiawuyongliang2.getText().toString().equals("") &&
                mujizhiyongliang2.getText().toString().equals("") &&
                chuliaodunxiangshuliang2.getText().toString() .equals("") &&
                chuyushaixiawuchashengliang2.getText().toString().equals("") &&
                jinliaodunxiangshuliang3.getText().toString().equals("") &&
                chulichuyuliang3.getText().toString().equals("") &&
                nitanyongliang3.getText().toString().equals("") &&
                ganhuachuyushaixiawuyongliang3.getText().toString().equals("") &&
                mujizhiyongliang3.getText().toString().equals("") &&
                chuliaodunxiangshuliang3.getText().toString() .equals("") &&
                chuyushaixiawuchashengliang3.getText().toString().equals("") &&
                jinliaodunxiangshuliang4.getText().toString().equals("") &&
                chulichuyuliang4.getText().toString().equals("") &&
                nitanyongliang4.getText().toString().equals("") &&
                ganhuachuyushaixiawuyongliang4.getText().toString().equals("") &&
                mujizhiyongliang4.getText().toString().equals("") &&
                chuliaodunxiangshuliang4.getText().toString() .equals("") &&
                chuyushaixiawuchashengliang4.getText().toString().equals("")
        ) {
            Toast.makeText(this, "请填写相关信息", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!jinliaodunxiangshuliang1.getText().toString().equals("") &&
                !Utility.isNumeric(jinliaodunxiangshuliang1.getText().toString())) {
            Toast.makeText(this, "1#进料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chulichuyuliang1.getText().toString().equals("") &&
                !Utility.isNumeric(chulichuyuliang1.getText().toString())) {
            Toast.makeText(this, "1#处理厨余量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!nitanyongliang1.getText().toString().equals("") &&
                !Utility.isNumeric(nitanyongliang1.getText().toString())) {
            Toast.makeText(this, "1#泥炭用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!ganhuachuyushaixiawuyongliang1.getText().toString().equals("") &&
                !Utility.isNumeric(ganhuachuyushaixiawuyongliang1.getText().toString())) {
            Toast.makeText(this, "1#干化厨余筛下物用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!mujizhiyongliang1.getText().toString().equals("") &&
                !Utility.isNumeric(mujizhiyongliang1.getText().toString())) {
            Toast.makeText(this, "1#木基质用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuliaodunxiangshuliang1.getText().toString().equals("") &&
                !Utility.isNumeric(chuliaodunxiangshuliang1.getText().toString())) {
            Toast.makeText(this, "1#出料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuyushaixiawuchashengliang1.getText().toString().equals("") &&
                !Utility.isNumeric(chuyushaixiawuchashengliang1.getText().toString())) {
            Toast.makeText(this, "1#厨余筛下物产生量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!jinliaodunxiangshuliang2.getText().toString().equals("") &&
                !Utility.isNumeric(jinliaodunxiangshuliang2.getText().toString())) {
            Toast.makeText(this, "2#进料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chulichuyuliang2.getText().toString().equals("") &&
                !Utility.isNumeric(chulichuyuliang2.getText().toString())) {
            Toast.makeText(this, "2#处理厨余量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!nitanyongliang2.getText().toString().equals("") &&
                !Utility.isNumeric(nitanyongliang2.getText().toString())) {
            Toast.makeText(this, "2#泥炭用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!ganhuachuyushaixiawuyongliang2.getText().toString().equals("") &&
                !Utility.isNumeric(ganhuachuyushaixiawuyongliang2.getText().toString())) {
            Toast.makeText(this, "2#干化厨余筛下物用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!mujizhiyongliang2.getText().toString().equals("") &&
                !Utility.isNumeric(mujizhiyongliang2.getText().toString())) {
            Toast.makeText(this, "2#木基质用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuliaodunxiangshuliang2.getText().toString().equals("") &&
                !Utility.isNumeric(chuliaodunxiangshuliang2.getText().toString())) {
            Toast.makeText(this, "2#出料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuyushaixiawuchashengliang2.getText().toString().equals("") &&
                !Utility.isNumeric(chuyushaixiawuchashengliang2.getText().toString())) {
            Toast.makeText(this, "2#厨余筛下物产生量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!jinliaodunxiangshuliang3.getText().toString().equals("") &&
                !Utility.isNumeric(jinliaodunxiangshuliang3.getText().toString())) {
            Toast.makeText(this, "3#进料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chulichuyuliang3.getText().toString().equals("") &&
                !Utility.isNumeric(chulichuyuliang3.getText().toString())) {
            Toast.makeText(this, "3#处理厨余量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!nitanyongliang3.getText().toString().equals("") &&
                !Utility.isNumeric(nitanyongliang3.getText().toString())) {
            Toast.makeText(this, "3#泥炭用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!ganhuachuyushaixiawuyongliang3.getText().toString().equals("") &&
                !Utility.isNumeric(ganhuachuyushaixiawuyongliang3.getText().toString())) {
            Toast.makeText(this, "3#干化厨余筛下物用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!mujizhiyongliang3.getText().toString().equals("") &&
                !Utility.isNumeric(mujizhiyongliang3.getText().toString())) {
            Toast.makeText(this, "3#木基质用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuliaodunxiangshuliang3.getText().toString().equals("") &&
                !Utility.isNumeric(chuliaodunxiangshuliang3.getText().toString())) {
            Toast.makeText(this, "3#出料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuyushaixiawuchashengliang3.getText().toString().equals("") &&
                !Utility.isNumeric(chuyushaixiawuchashengliang3.getText().toString())) {
            Toast.makeText(this, "3#厨余筛下物产生量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!jinliaodunxiangshuliang4.getText().toString().equals("") &&
                !Utility.isNumeric(jinliaodunxiangshuliang4.getText().toString())) {
            Toast.makeText(this, "4#进料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chulichuyuliang4.getText().toString().equals("") &&
                !Utility.isNumeric(chulichuyuliang4.getText().toString())) {
            Toast.makeText(this, "4#处理厨余量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!nitanyongliang4.getText().toString().equals("") &&
                !Utility.isNumeric(nitanyongliang4.getText().toString())) {
            Toast.makeText(this, "4#泥炭用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!ganhuachuyushaixiawuyongliang4.getText().toString().equals("") &&
                !Utility.isNumeric(ganhuachuyushaixiawuyongliang4.getText().toString())) {
            Toast.makeText(this, "4#干化厨余筛下物用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!mujizhiyongliang4.getText().toString().equals("") &&
                !Utility.isNumeric(mujizhiyongliang4.getText().toString())) {
            Toast.makeText(this, "4#木基质用量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuliaodunxiangshuliang4.getText().toString().equals("") &&
                !Utility.isNumeric(chuliaodunxiangshuliang4.getText().toString())) {
            Toast.makeText(this, "4#出料吨箱数量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!chuyushaixiawuchashengliang4.getText().toString().equals("") &&
                !Utility.isNumeric(chuyushaixiawuchashengliang4.getText().toString())) {
            Toast.makeText(this, "4#厨余筛下物产生量格式错误", Toast.LENGTH_SHORT).show();
            return;
        }
        new AlertDialog.Builder(this)
                .setTitle("确定提交吗？")
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) ->
                        Toast.makeText(this, "取消提交", Toast.LENGTH_SHORT).show()))
                .setPositiveButton("确定", (dialog, which) -> {
                    // 提交表单
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/compostCraft/add";

                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");

                                        if (code.startsWith("2"))
                                            Toast.makeText(duifeigongyi.this,
                                                    "提交成功", Toast.LENGTH_SHORT).show();
                                        else
                                            Toast.makeText(duifeigongyi.this,
                                                    "提交失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(duifeigongyi.this,
                                    "提交失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() {
                            Map<String, String> map=new HashMap<>();
                            map.put("date", dateEdit.getText().toString());
                            map.put("tontankFeed1", jinliaodunxiangshuliang1.getText().toString());
                            map.put("disposalKitchenWaste1", chulichuyuliang1.getText().toString());
                            map.put("peat1", nitanyongliang1.getText().toString());
                            map.put("driedKitchenWaste1", ganhuachuyushaixiawuyongliang1.getText().toString());
                            map.put("woodMatrix1", mujizhiyongliang1.getText().toString());
                            map.put("dischargeTonBox1", chuliaodunxiangshuliang1.getText().toString());
                            map.put("kitchenWasteUnderSieve1", chuyushaixiawuchashengliang1.getText().toString());
                            map.put("tontankFeed2", jinliaodunxiangshuliang2.getText().toString());
                            map.put("disposalKitchenWaste2", chulichuyuliang2.getText().toString());
                            map.put("peat2", nitanyongliang2.getText().toString());
                            map.put("driedKitchenWaste2", ganhuachuyushaixiawuyongliang2.getText().toString());
                            map.put("woodMatrix2", mujizhiyongliang2.getText().toString());
                            map.put("dischargeTonBox2", chuliaodunxiangshuliang2.getText().toString());
                            map.put("kitchenWasteUnderSieve2", chuyushaixiawuchashengliang2.getText().toString());
                            map.put("tontankFeed3", jinliaodunxiangshuliang3.getText().toString());
                            map.put("disposalKitchenWaste3", chulichuyuliang3.getText().toString());
                            map.put("peat3", nitanyongliang3.getText().toString());
                            map.put("driedKitchenWaste3", ganhuachuyushaixiawuyongliang3.getText().toString());
                            map.put("woodMatrix3", mujizhiyongliang3.getText().toString());
                            map.put("dischargeTonBox3", chuliaodunxiangshuliang3.getText().toString());
                            map.put("kitchenWasteUnderSieve3", chuyushaixiawuchashengliang3.getText().toString());
                            map.put("tontankFeed4", jinliaodunxiangshuliang4.getText().toString());
                            map.put("disposalKitchenWaste4", chulichuyuliang4.getText().toString());
                            map.put("peat4", nitanyongliang4.getText().toString());
                            map.put("driedKitchenWaste4", ganhuachuyushaixiawuyongliang4.getText().toString());
                            map.put("woodMatrix4", mujizhiyongliang4.getText().toString());
                            map.put("dischargeTonBox4", chuliaodunxiangshuliang4.getText().toString());
                            map.put("kitchenWasteUnderSieve4", chuyushaixiawuchashengliang4.getText().toString());
                            map.put("remark", comment.getText().toString());
                            Log.d("factory", factory);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);

                }).show();
    }
}